package com.gljx.web.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gljx.web.Entity.Car;
import com.gljx.web.dao.CarMapper;
import com.gljx.web.dao.CommonDao;
import com.gljx.web.service.CarService;
@Service
@Transactional
public class CarServiceImpl  extends CommonDao implements CarService{

	@Autowired
	private CarMapper carMapper;
	
	/**
	 *取分页数据    dmz 20160921
	 *@param pindex 页码
	 *@param psql SQL语句，需要带 rownum rn 例如：select rownum rn,t.* from zzda t
	 *@param psize 每页记录数
	 * */
	@Override
	public Map<String, Object> selectPage(int pindex, String psql, int psize) {
		  Map<String, Object> paramMap = new HashMap<String, Object>();
	       paramMap.put("Pindex", pindex);
	       paramMap.put("Psql", psql);
	       paramMap.put("Psize", psize);
	       paramMap.put("Pcount", oracle.jdbc.OracleTypes.INTEGER);
	       paramMap.put("v_cur", oracle.jdbc.OracleTypes.CURSOR);
	       this.getSqlSession().select("com.gljx.web.dao.CarMapper.pagemap", paramMap, null);
	       return  paramMap;
	}

	/**
	 * 取记录总数      dmz 20160921
	 * @param psql   SQL语句
	 * @return
	 */
	@Override
	public Map<String, Object> selectPageCount(String psql) {
		   Map<String, Object> paramMap = new HashMap<String, Object>();
	       paramMap.put("Psql", psql);
	       paramMap.put("Pcount", oracle.jdbc.OracleTypes.INTEGER);
	       this.getSqlSession().select("com.gljx.web.dao.CarMapper.pagecount", paramMap, null);
	       return paramMap;
	}

	/**
	 * 实现根据fid删除的方法
	 */
	@Override
	public void deleteByPrimaryKey(String fid) {
		// TODO Auto-generated method stub
		carMapper.deleteByPrimaryKey(fid);
	}

	/**
	 * 实现根据车牌号码查询
	 */
	@Override
	public List<Car> queryCarByFnumber(String fnumber,String companyId) {
		// TODO Auto-generated method stub
		Map<String, String> map = new HashMap<>();
		map.put("fnumber", fnumber);
		map.put("cfficompanyid", companyId);
		return carMapper.selectCarByFnumber(map);
	}

	/**
	 * 实现添加方法
	 */
	@Override
	public void addCar(Car car) {
		// TODO Auto-generated method stub
		carMapper.insertSelective(car);
	}

	/**
	 * 实现根据fid查询方法
	 */
	@Override
	public Car queryCarByFid(String fid) {
		// TODO Auto-generated method stub
		return carMapper.selectByPrimaryKey(fid);
	}

	/**
	 * 实现修改车辆信息方法
	 */
	@Override
	public void modifyCarByFid(Car car) {
		// TODO Auto-generated method stub
		carMapper.updateByPrimaryKeySelective(car);
	}
	
	/**
	 * 查询所有
	 */
	@Override
    public List<Car> queryCar(String compangId) {
        // TODO Auto-generated method stub
        return carMapper.selectCarAll(compangId);
    }

	@Override
    public List<Car> queryCarByName(String name, String compangId) {
        // TODO Auto-generated method stub
        Map<String, String> map = new HashMap<>();
        map.put("name", name);
        map.put("companyId", compangId);
        return carMapper.selectCarByName(map);
    }

	@Override
	public List<Car> queryCarByInfo(String name,String fnumber) {
		// TODO Auto-generated method stub
		Map<String, String> map = new HashMap<>();
		map.put("fnumber", fnumber);
		map.put("fnameL2", name);
		return carMapper.selectCarByInfo(map);
	}

	@Override
	public String selectCarFnumber(String fnumber, String companyId) {
		// TODO Auto-generated method stub
		Map<String, String> map = new HashMap<>();
		map.put("fnumber", fnumber);
		map.put("companyId", companyId);
		return carMapper.selectCarFnumber(map);
	}

	@Override
	public List<Car> selectCarExcel(String fnumber, String fcompanyid) {
		Map<String, String> map = new HashMap<>();
		map.put("fnumber", fnumber);
		map.put("cfficompanyid", fcompanyid);
		return carMapper.selectCarExcel(map);
	}


}
